package com.mcxx.modules.system.controller;

import com.alibaba.fastjson.JSON;
import com.mcxx.modules.system.service.IssuingBankService;
import com.mcxx.modules.miniSalvation.family.param.OrganizationParam;
import com.mcxx.modules.system.param.IssuingBankParam;
import com.mcxx.modules.system.service.read.IssuingBankReadService;
import com.mcxx.service.DefaultRestService;
import com.mcxx.util.FileExportUtil;
import com.yinhai.ta404.component.audit.vo.ExcelInfo;
import com.yinhai.ta404.core.restservice.annotation.RestService;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Validated
@Api("数据管理/代发银行查询")
@RestService({"dataManage/IssuingBank/v2"})
public class IssuingBankController extends DefaultRestService {
    @Autowired
    private IssuingBankReadService issuingBankReadService;

    @Autowired
    private IssuingBankService issuingBankService;


    @PostMapping("queryIssuingBankList")
    @ApiOperation("查询代发银行列表")
    public void queryIssuingBankList(IssuingBankParam param, PageParam pageParam){
        log.info("查询代发银行列表，参数是：{}", param);
        UserAccountVo userAccountVo = getCurUserAccount();
        Page page = issuingBankReadService.queryIssuingBankList(param,pageParam,userAccountVo);
        this.setPageBean(page);
        log.info("查询代发银行列表，参数是：{}", param);
    }

    @PostMapping("downLoadIssuingBankList")
    @ApiOperation("代发银行列表导出")
    public void downLoadIssuingBankList(HttpServletResponse response, @RequestBody IssuingBankParam param)throws IOException {
        log.info("代发银行列表导出开始 参数{}", JSON.toJSONString(param));
        ExcelInfo excelInfo = issuingBankService.exportIssuingBankList(param,getCurUserAccount());
        if(null != excelInfo){
            FileExportUtil.exportFileResponse(response, excelInfo, getCurUserAccount().getAreaName());
//            ZipInfoUtil.exportZipResponse(response, excelInfo, this.getCurUserId());
        }
        log.info("代发银行列表导出结束 参数{}", excelInfo);
    }



}
